package br.uff.es2.xadrez.core;


//LINHA DE TESTE PARA O COMMITED
public class Bishop extends Piece {

    public Bishop(Color color, String imageFilePath) {
        this.color = color;
        this.imageFilePath = imageFilePath;
        this.value = 4;
    }

    @Override
    public int[][] getAvaiableMoves(int[] posicao, Piece[][] board) {
        boolean blockUpRight = false;
        boolean blockUpLeft = false;
        boolean blockDownRight = false;
        boolean blockDownLeft = false;
        int[][] availableMoves = new int[8][8];
        for (int x = 1; x < 8; x++) {
            if (posicao[0]+x < 8 && posicao[1]+x < 8 && !blockDownRight) {
                if (board[posicao[0]+x][posicao[1]+x] == null) {
                    availableMoves[posicao[0]+x][posicao[1]+x] = 1;
                } else {
                    blockDownRight = true;
                    if (board[posicao[0]+x][posicao[1]+x].getColor() != getColor()) {
                        availableMoves[posicao[0]+x][posicao[1]+x] = 1;
                    }
                }
            }
            if (posicao[0]-x >= 0 && posicao[1]-x >= 0 && !blockUpLeft) {
                if (board[posicao[0]-x][posicao[1]-x] == null) {
                    availableMoves[posicao[0]-x][posicao[1]-x] = 1;
                } else {
                    blockUpLeft = true;
                    if (board[posicao[0]-x][posicao[1]-x].getColor() != getColor()) {
                        availableMoves[posicao[0]-x][posicao[1]-x] = 1;
                    }
                }
            }
            if (posicao[0]+x < 8 && posicao[1]-x >= 0 && !blockDownLeft) {
                if (board[posicao[0]+x][posicao[1]-x] == null) {
                    availableMoves[posicao[0]+x][posicao[1]-x] = 1;
                } else {
                    blockDownLeft = true;
                    if (board[posicao[0]+x][posicao[1]-x].getColor() != getColor()) {
                        availableMoves[posicao[0]+x][posicao[1]-x] = 1;
                    }
                }
            }
            if (posicao[0]-x >= 0 && posicao[1]+x < 8 && !blockUpRight) {
                if (board[posicao[0]-x][posicao[1]+x] == null) {
                    availableMoves[posicao[0]-x][posicao[1]+x] = 1;
                } else {
                    blockUpRight = true;
                    if (board[posicao[0]-x][posicao[1]+x].getColor() != getColor()) {
                        availableMoves[posicao[0]-x][posicao[1]+x] = 1;
                    }
                }
            }
        }
        return availableMoves;
    }

}
